package offer;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


class MedianFinder {
    List<Integer> list = new ArrayList<>();
    /** initialize your data structure here. */
    public MedianFinder() {

    }

    public void addNum(int num) {
        list.add(num);
    }

    public double findMedian() {
        int left = 0;
        int right = list.size()-1;
        int mid = 0;
        double res=0;
        Collections.sort(list);
        if(list.size()%2!=0)
        {
            mid = (left+right)/2;
           res = list.get(mid);
        }else if(list.size()%2==0){
            mid = (left+right)/2;
            int x = list.get(mid);
            int y = list.get(mid+1);

            res  =(double) (x+y)/2;
        }
        return res;
    }
}
public class offer41 {
    public static void main(String[] args) {
        MedianFinder m = new MedianFinder();
        m.addNum(1);
        m.addNum(2);
        double median = m.findMedian();
        System.out.println(median);
    }
}